package com.example.rabbit.consumer;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;
import java.util.Date;

/**
 * 监听器 第二种写法
 * 1.RabbitListener 注解写在class类上，并设置默认成功回调处理函数
 *
 * @author dell
 * @date 2022/08/10
 */
@Slf4j
//@Component
@RabbitListener(queues = "dead_letter_queue")
public class DeadLetterConsumer2 {


    @RabbitHandler(isDefault = true)
    public void receiveDeadLetterMessage2(Message message, Channel channel) {

        String msg = new String(message.getBody(), StandardCharsets.UTF_8);
        log.info("方式二.监听死信队列。当前时间, {},收到消息:{}", new Date().toString(), msg);
    }


    @RabbitListener(queues = "queue_a")
    public void receiveQueueA(Message message, Channel channel) {
        String msg = new String(message.getBody(), StandardCharsets.UTF_8);
        log.info("监听queue_a队列.当前时间, {},收到消息:{}", new Date().toString(), msg);
    }
}
